<template>
<div>
  <el-row>
     <el-col :span="24" class="demo-handle">
           <el-form :model='queryform' :inline="true" class="demo-form-inline">
                <el-form-item>
                    <el-input v-model="queryform.projectName" placeholder="项目标题"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="info" icon='search' @click='queryProject'>查询</el-button>
                </el-form-item>
            </el-form>
        </el-col>
  </el-row>
  <el-row>
    <el-table
      highlight-current-row
      :row-key="getRowKeys"
      :expand-row-keys="expands"
      :data="proData">
      <el-table-column
        type="index"
        width="60">
      </el-table-column>
      <el-table-column type="expand">
        <template scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="项目状态">
                <span>{{ props.row.proState }}</span>
              </el-form-item>
            <el-form-item label="创建时间">
              <span>{{ props.row.createDate }}</span>
            </el-form-item>
            <el-form-item label="最近更新人">
              <span>{{ props.row.lastUpdator }}</span>
            </el-form-item>
            <el-form-item label="最近更新时间">
              <span>{{ props.row.lastUpdateDate }}</span>
            </el-form-item>
            <el-form-item label="项目说明">
              <span>{{ props.row.desc }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        label="项目名称"
        prop="projectName">
      </el-table-column>
      <el-table-column
        label="创建人"
        prop="creator" width="100">
      </el-table-column>
      <el-table-column
        label="重要程度"
        prop="importance" width="300">
        <template scope="props">
        <el-rate
          v-model="props.row.importance"
          :max=10
          :low-threshold=3
          :high-threshold=8
          disabled
          :colors="['#13CE66', '#F7BA2A', '#FF4949']">
          {{props.row.importance}}
        </el-rate>
        </template>
      </el-table-column>
      <el-table-column
        label="工作量"
        prop="workNum" width="100">
        <template scope="props">
          <span>{{props.row.workNum}}小时</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150">
        <template scope="scope">
        <el-button
            size="small"
            type="info"
            @click="handleThings(scope.$index, scope.row)">事件时间轴</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-row>
</div>
</template>

<style>
  .demo-handle{
    padding-top: 20px;
    padding-left: 20px;
  }
  .demo-form-inline{
    display: inline-block;
    float: right;
  }
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 120px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

<script>
  import projectedit from './project-edit'
  import axios from 'axios'
  export default {
    data () {
      return {
         // 获取row的key值
        getRowKeys (row) {
          return row.id
        },
        ruleForm: {},
        queryform: {
          projectName: ''
        },
        isvisible: false,
        ops: '',
        // 要展开的行，数值的元素是row的key值
        expands: [],
        proData: []
      }
    },
    components: {
      projectedit
    },
    methods: {
      handleThings (index, row) {
        let vm = this
        axios.get('/projectmanage/thing/timelineList', {
          params: {
            proId: row.id
          }
        }).then(function (res) {
          if (res.data.success === true) {
            vm.$store.commit('updateThings', res.data.data)
          }
        })
        this.$router.replace('/timeline')
      },
      getProject () {
        let vm = this
        axios.get('/projectmanage/project/projectList').then(function (res) {
          if (res.data.success === true) {
            vm.proData = res.data.data
          }
        })
      },
      queryProject () {
        let vm = this
        axios.get('/projectmanage/project/queryProject', {
          params: this.queryform
        }).then(function (res) {
          if (res.data.success === true) {
            vm.proData = res.data.data
          }
        })
      }
    },
    mounted () {
      this.getProject()
      // 在这里你想初始化的时候展开哪一行都可以了
      // this.ruleForm = Object.assign({}, this.proData[0])
      // this.expands.push(this.proData[0].id)
    }
  }
</script>